﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BabyToys.Models;
using System.Data;
using BabyToys.Models.ViewModel;
namespace BabyToys.DAL
{
    public class RegisterDAL
    {
        DatabaseContext db = new DatabaseContext();
        public void ThemKhachHang(KhachHangViewModel register)
        {
            KhachHang khachhang = new KhachHang();
            khachhang.TenDangNhap = register.TenDangNhap;
            khachhang.TenDayDu = register.TenDayDu;
            khachhang.MatKhau = BabyToys.Utilities.EditString.mahoa_md5(register.MatKhau);
            khachhang.Email = register.Email;
            khachhang.DiaChi = register.DiaChi;
            khachhang.SoDienThoai = register.SoDienThoai;
            khachhang.IdLoaiKhachHang = register.IdLoaiKhachHang;
            khachhang.IsActive = true;
            //khachhang.IsOnline = false;
            db.KhachHangs.Add(khachhang);
            db.SaveChanges();
        }
        public void SuaKhachHang(KhachHangViewModel register)
        {
            KhachHang khachhang = new KhachHang();
            khachhang.IdKhachHang = register.Id;
            khachhang.TenDangNhap = register.TenDangNhap;
            khachhang.TenDayDu = register.TenDayDu;
            khachhang.MatKhau = BabyToys.Utilities.EditString.mahoa_md5(register.MatKhau);
            khachhang.Email = register.Email;
            khachhang.DiaChi = register.DiaChi;
            khachhang.SoDienThoai = register.SoDienThoai;
            khachhang.IdLoaiKhachHang = register.IdLoaiKhachHang;
            khachhang.IsActive = true;
            //khachhang.IsOnline = false;
            db.Entry(khachhang).State = EntityState.Modified;
            db.SaveChanges();
        }
        public void ThemNhanVien(NhanVienViewModel register)
        {
            User user = new User();
            user.TenDangNhap = register.TenDangNhap;
            user.TenDayDu = register.TenDayDu;
            user.MatKhau = BabyToys.Utilities.EditString.mahoa_md5(register.MatKhau);
            user.Email = register.Email;
            user.DiaChi = register.DiaChi;
            user.SoDienThoai = register.SoDienThoai;
            user.IdQuyen = register.IdQuyen;
            user.IsActive = true;
            user.IsOnline = false;
            db.Users.Add(user);
            db.SaveChanges();
        }
        public void SuaNhanVien(NhanVienViewModel register)
        {
            User user = new User();
            user.Id = register.Id;
            user.TenDangNhap = register.TenDangNhap;
            user.TenDayDu = register.TenDayDu;
            user.MatKhau = BabyToys.Utilities.EditString.mahoa_md5(register.MatKhau);
            user.Email = register.Email;
            user.DiaChi = register.DiaChi;
            user.SoDienThoai = register.SoDienThoai;
            user.IdQuyen = register.IdQuyen;
            user.IsActive = register.IsActive;
            //user.IsOnline = false;
            db.Entry(user).State = EntityState.Modified;
            db.SaveChanges();
        }
    }
}